<template>
  <div id="player" >
  </div>
</template>

<script>

  import { CloudRenderer } from "@/components/PSPlayer/superapi.js";

  import {
    isOk
  } from '@/utils/request'

  import {
    getOrder,
  } from '@/api/cloud/render'

  export default {
    name:'Editor',
    components: {
    },
    data() {
      return {
        cloudRender:null,
        scene:{},
        init:{
          loading:true,
          loadingText:''
        },
        currentCameraInfo:undefined
      }
    },
    computed: {
    },
    mounted(){
    },
    created() {
     // this.cloudRender = new cloudRenderer("player", 0);
      this.getOrder();
    },
    beforeDestroy() {
    },
    methods: {
      getOrder(){
        // this.init.loadingText='获取云渲染资源...'
        getOrder({order:this.$route.query.renderId, width:window.innerWidth, height:window.innerHeight}).then(rsp => {
          console.log(rsp)
          if(200==rsp.code){
            const _data=rsp.result
            let cloudRender = new CloudRenderer('player');

            cloudRender.SuperAPI("StartRenderCloud",_data.url);



          }
        }).catch(err => {
          console.log(err);
        })
        .finally(() => {
        })
      },
      showSceneSrcById(id){
        getSceneSrcById({
          id:id
        }).then(rsp => {
          if (rsp.code==200) {
            const _data = rsp.data
            for(var i in _data){
              this.addRender(_data[i])
            }
          }
        })
      },
      hideSceneSrcById(id){
        getSceneSrcById({
          id:id
        }).then(rsp => {
          if (rsp.code==200) {
            const _data = rsp.data
            for(var i in _data){
              this.removeRender(_data[i]);
            }
          }
        })
      },
      showSceneSrcByMenuId(menuId,code){
        getSceneLayerSrcById({
          layerId:menuId,
          code:code
        }).then(rsp => {
          if (rsp.code==200) {
            const _data = rsp.data
            for(var i in _data){
              this.addRender(_data[i])
            }
          }
        })
      },
      hideSceneSrcByMenuId(menuId){
          getSceneLayerSrcById({
           layerId:menuId
          }).then(rsp => {
            if (rsp.code==200) {
              const _data = rsp.data
              for(var i in _data){
                this.removeRender(_data[i]);
              }
            }
          })
      },
      addRender(_data){
        if('POI'==_data.type){
          if('0'==_data.data.type){
            if(_data.data.data.window==null || Object.keys(_data.data.data.window).length<=0 ){
              delete _data.data.data.window
            }
            if(_data.data.data.label==null || Object.keys(_data.data.data.label).length<=0 ){
              delete _data.data.data.label
            }
            this.cloudRender.SuperAPI("AddCustomPOI", _data.data.data, (status) => {
            })
          }
          else if('1'==_data.data.type) {
            this.cloudRender.SuperAPI("AddPOI", _data.data.data, (status) => {
            })
          }
          else if('2'==_data.data.type){
            this.cloudRender.SuperAPI("AddEffect", _data.data.data, (status) => {
            })
          }
        }
        else if('PATH'==_data.type){
          this.cloudRender.SuperAPI("AddPath", _data.data, (status) => {
          })
        }
        else if('RANGE'==_data.type){
          this.cloudRender.SuperAPI("AddRange", _data.data, (status) => {
          })
        }
      },
      removeRender(_data){
        if('POI'==_data.type){
          if('0'==_data.data.type){
            this.cloudRender.SuperAPI("RemoveCovering",{
                  "id":_data.id,
                  "covering_type":"poi"
              }, (status) => {
            })
          }
          else if('1'==_data.data.type) {
            this.cloudRender.SuperAPI("RemoveCovering",{
                  "id":_data.id,
                  "covering_type":"poi"
              }, (status) => {
            })
          }
          else if('2'==_data.data.type){
            this.cloudRender.SuperAPI("RemoveCovering",{
                  "id":_data.id,
                  "covering_type":"scene_effect"
              }, (status) => {
            })
          }
        }
        else if('PATH'==_data.type){
          this.cloudRender.SuperAPI("RemoveCovering",{
                "id":_data.id,
                "covering_type":"path"
            }, (status) => {
          })
        }
        else if('RANGE'==_data.type){
          this.cloudRender.SuperAPI("RemoveCovering",{
                "id":_data.id,
                "covering_type":"range"
            }, (status) => {
          })
        }
      }
    }
  }
</script>

<style lang="scss">

  .begin {
      text-align: center;
      font-size: 14px;
      padding: 0;
      position: fixed;
      left: 50%;
      top: 40%;
      transform: translate(-50%, -40%);
      user-select: none;
  }

  #player{
    background: #111;
    position:absolute !important;
    z-index: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #25262a;
  }

</style>
